Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify ninjas on their birthday #155

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

pedrofp4444
Copy link
Member

No description provided.

@pedrofp4444 pedrofp4444 marked this pull request as draft January 13, 2023 16:49
@pedrofp4444 pedrofp4444 self-assigned this Jan 13, 2023
lib/bokken/application.ex Outdated Show resolved Hide resolved
lib/bokken/periodically.ex Outdated Show resolved Hide resolved
lib/bokken_web/controllers/ninja_controller.ex Outdated Show resolved Hide resolved
@pedrofp4444 pedrofp4444 marked this pull request as ready for review January 20, 2023 23:33
Copy link
Member

@ruilopesm ruilopesm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a guardian can have more than one ninja, it would make sense to identify the ninja (by its first and last names) on the email body 🙏🏼

mix.exs Outdated Show resolved Hide resolved
@pedrofp4444
Copy link
Member Author

I haven´t used the "family name" because much probably it will be the same for both ninjas and using only the first one the email looks more personalized.

lib/bokken/events/event_admin.ex Outdated Show resolved Hide resolved
lib/bokken/accounts.ex Outdated Show resolved Hide resolved
lib/bokken/application.ex Outdated Show resolved Hide resolved
lib/bokken/birthdaynotifier.ex Outdated Show resolved Hide resolved
pedrofp4444 and others added 2 commits March 14, 2023 18:18
Comment on lines +14 to +23
ninjas
|> Enum.filter(fn ninja ->
ninja.birthday.month == current_time.month && ninja.birthday.day == current_time.day &&
not is_nil(ninja.user)
end)
|> Enum.map(fn ninja -> ninja.user end)
|> send_email(fn user ->
EventsEmails.ninja_birthday_email(user.ninja,
to: Accounts.get_guardian_email_by_ninja(ninja: user)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The situation is as follows. Currently not a single ninja has a registered account, meaning this is basically useless. What we could do is send the email to the guardian if the ninja does not have an account associated with them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But Ninjas are not even supposed to have emails, when I'm using the .email I thought I was sending it to the guardians right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But ninja.user is nil, meaning you won't send it regardless. It works fine locally because we don't have ninjas without users associated with them (but we should)

Comment on lines +51 to +65
def send_email(users, email) do
users
|> Enum.reduce(
%{success: [], fail: []},
fn user, accumulator ->
case Mailer.deliver(email.(user)) do
{:ok, _} ->
%{success: [user.email | accumulator[:success]], fail: accumulator[:fail]}

{:error, _} ->
%{success: [accumulator[:success]], fail: [user.email | accumulator[:fail]]}
end
end
)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR in particular, but I am seeing this function used and duplicated in many different contexts. I think we should create an utils file and put it there. What do you think @RuiL1904?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@ruioliveira02
Copy link
Member

Solve the conflicts when you can 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

5 participants